package com.zjzywl.smoke.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
/*
 * 烟感大数据--报警来源，报警原因的详细数据
 */
import java.util.List;

import javax.websocket.server.PathParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zjzywl.smoke.authenticate.AuthUser;
import com.zjzywl.smoke.repository.AlarmRepository;
import com.zjzywl.smoke.util.WebResult;

@RestController
@RequestMapping(value = "/detailed")
public class DetailedInformationController extends BaseController {
	@Autowired
	private AlarmRepository repository;

	// 报警来源的详细数据
	@RequestMapping(value = "/source")

	public WebResult getAlarmSource(@PathParam("beginTime") String beginTime, @PathParam("endTime") String endTime,
			@PathParam("alarmTypeCode") String alarmTypeCode, @PathParam("deviceTypeId") String deviceTypeId,
			@PathParam("fixedPlace") String fixedPlace) {
		String bTime = beginTime;
		String eTime = endTime;
		String userId = this.getUserId();
		List alarmCountByDevice = repository.getAlarmCountByDevice(bTime, eTime, 0, alarmTypeCode, deviceTypeId, userId,
				fixedPlace);
		return WebResult.OK(alarmCountByDevice);
	}

	// 报警原因的详细数据
	@RequestMapping(value = "/reason")

	public WebResult getAlarmReason(@PathParam("beginTime") String beginTime, @PathParam("endTime") String endTime,
			@PathParam("alarmCode") String alarmCode, @PathParam("alarmReasons") String alarmReasons)
			throws ParseException {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date bTime = format.parse(beginTime);
		Date eTime = format.parse(endTime);
		AuthUser userId = this.getLoginUser();
		String disposePeople = userId.getPeople().getName();
		List alarmCountByDevice = new ArrayList();
		if (alarmReasons != null) {
			alarmCountByDevice = repository.getAlarmReason(bTime, eTime, alarmCode, alarmReasons, disposePeople);
		} else {
			alarmCountByDevice = repository.getAlarmReason(bTime, eTime, alarmCode, disposePeople);
		}
		return WebResult.OK(alarmCountByDevice);

	}
}
